import axios from "axios";
import NProgress from "nprogress";
const mockIns = axios.create({
    baseURL: '/mock',
    timeout: 3000
})


//添加拦截器
mockIns.interceptors.request.use(function (config) {
    //在请求开始前，开启进度条
    NProgress.start()
    return config;
})
mockIns.interceptors.response.use(function (response) {
    NProgress.done()
    if (response.request.custom.url === '/mock/floors') {
        let { data } = response.data
        data.forEach(item => {
            item.carouselList = item.carouselList.map(item => ({ id: item.id, url: item.imgUrl }))
        });
    }
    return response.data;
}, function (error) {
    NProgress.done()
    return Promise.reject(error);
})

export default mockIns